<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/templates/template.xhtml">
	<p:growl id="growl" showDetail="true" sticky="true" />
	<ui:define name="title">
		Manter Pessoas
	</ui:define>

	<ui:define name="head">
		<style type="text/css">
#panelGrid1 {
	width: 100%;
	border-style: none;
	border-width: 0px;
}

.colunaPanelGrid1 {
	border-width: 0px;
	border-style: none;
}

.colDir {
	text-align: right;
}

.colEsq {
	text-align: left;
}
</style>

	</ui:define>

	<ui:define name="centro">
		<h:form id="form1" prependId="false">
			<p:panel id="painelEdicao" >
				<f:facet name="header">
					<h:outputText value="Manter Pessoa" />
				</f:facet>
				<h:panelGrid columns="2" width="99%">
				<h:panelGrid columns="2" width="70%">

					<p:selectOneRadio id="radioPessoa"
						value="#{manterPessoaMB.pessoaEnum}" style="width:120px;">
						<f:selectItems value="#{manterPessoaMB.listaPessoas}" var="pessoa"
							itemLabel="#{pessoa.descricao}" itemValue="#{pessoa}" />
						<p:ajax process="radioPessoa" event="change"
							update="panelCNPJ panelCNPJ2 panelCPF panelCPF2 panelRazao panelRazao2"
							listener="#{manterPessoaMB.doCancelarAction}" />
					</p:selectOneRadio>
					
					<p:spacer />
					
					<h:outputLabel value="#{lbls.LBL_0005}:"
						rendered="#{manterPessoaMB.editarState or manterPessoaMB.detalharState}" />
					<h:outputText style="font-weight:bold; font-size:large;"
						value="#{manterPessoaMB.pessoa.id}"
						rendered="#{manterPessoaMB.editarState or manterPessoaMB.detalharState}">
						<f:convertNumber pattern="000000" />
					</h:outputText>

					<h:outputLabel value="#{lbls.LBL_0010}:" for="txtNome" />
					<p:inputText label="#{lbls.LBL_0010}"
						value="#{manterPessoaMB.pessoa.nome}" id="txtNome" maxlength="50"
						size="50">
					</p:inputText>
					<h:panelGroup id="panelRazao">		
						<h:outputLabel rendered="#{manterPessoaMB.pessoaJuridica}"
							id="labelRazaoSocial" value="#{lbls.LBL_0070}:"
							for="txtRazaoSocial" />
					</h:panelGroup>
					<h:panelGroup id="panelRazao2">
						<p:inputText label="#{lbls.LBL_0070}"
							rendered="#{manterPessoaMB.pessoaJuridica}"
							value="#{manterPessoaMB.pessoa.razaoSocial}" id="txtRazaoSocial"
							maxlength="50" size="50" />
					</h:panelGroup>

					<h:panelGroup id="panelCNPJ">
						<h:outputLabel rendered="#{manterPessoaMB.pessoaJuridica}"
							id="labelCNPJ" value="#{lbls.LBL_0072}:" for="txtCNPJ" />
					</h:panelGroup>
					<h:panelGroup id="panelCNPJ2">
						<p:inputText label="#{lbls.LBL_0072}"
							rendered="#{manterPessoaMB.pessoaJuridica}"
							value="#{manterPessoaMB.pessoa.cnpj}" id="txtCNPJ" 
							maxlength="18" size="18" 
							onkeypress="if (somenteNumero(event)) mascaraCpfCnpj(this); else return false;"
							onkeyup="if (somenteNumero(event)) mascaraCpfCnpj(this); else return false;"
							onblur="if (somenteNumero(event)) mascaraCpfCnpj(this); else return false;"/>
					</h:panelGroup>

					<h:panelGroup id="panelCPF">
						<h:outputLabel for="txtCPF" id="labelCPF"
							value="#{lbls.LBL_0071}:"
							rendered="#{manterPessoaMB.pessoaFisica}" />
					</h:panelGroup>
					<h:panelGroup id="panelCPF2">
						<p:inputText label="#{lbls.LBL_0071}"
							rendered="#{manterPessoaMB.pessoaFisica}"
							value="#{manterPessoaMB.pessoa.cpf}" id="txtCPF" maxlength="11"
							size="11" />
					</h:panelGroup>

					<h:outputLabel value="#{lbls.LBL_0066}:" for="txtFoneComercial" id="lblFoneComercial"/>
					<p:inputText id="txtFoneComercial" size="10" maxlength="10"
						value="#{manterPessoaMB.pessoa.foneComercial}" />

					<h:outputLabel value="#{lbls.LBL_0068}:" for="txtFoneCelular" />
					<p:inputText id="txtFoneCelular" size="10" maxlength="10"
						value="#{manterPessoaMB.pessoa.foneCelular}" />

					<h:outputLabel value="#{lbls.LBL_0067}:" for="txtFoneResidencial" />
					<p:inputText id="txtFoneResidencial" size="10" maxlength="10"
						value="#{manterPessoaMB.pessoa.foneResidencial}" />

					<h:outputLabel value="#{lbls.LBL_0073}:" for="txtEmail" />
					<p:inputText id="txtEmail" size="40"
						value="#{manterPessoaMB.pessoa.email}" />

				</h:panelGrid>
				
				<h:panelGrid columns="2" width="25%">
					<p:fieldset legend="#{lbls.LBL_0074}" style="margin-left:10px;">
						 <p:pickList id="pickListTipoPessoa" value="#{manterPessoaMB.tiposPessoa}"  
				                var="tipo" converter="pickListConverter" 
				                itemLabel="#{tipo.descricao}"  
				                itemValue="#{tipo}" />  				
					</p:fieldset>
					</h:panelGrid>
				</h:panelGrid>



				<f:facet name="footer">
					<p:commandButton value="#{lbls.LBL_0002}" icon="ui-icon-check"
						update="painelEdicao, pessoaDataTable" action="#{manterPessoaMB.doSalvarAction}" />

					<p:commandButton value="#{lbls.LBL_0003}" icon="ui-icon-cancel"
						update="painelEdicao, pessoaDataTable" action="#{manterPessoaMB.doCancelarAction}"
						process="@this" />

					<p:commandButton value="#{lbls.LBL_0076}" icon="ui-icon-cancel"
						update="pessoaDataTable" 
						action="#{manterPessoaMB.listarPorExemplo}" />

					<p:commandButton id="showDialogButton" value="#{lbls.LBL_0013}"
						style="float:right" icon="ui-icon-trash"
						rendered="#{manterPessoaMB.detalharState}"
						onclick="confirmation.show()" type="button" />

				</f:facet>

				<p:confirmDialog id="confirmDialog" message="#{msgs.MSG_0002}"
					appendToBody="true" header="#{msgs.MSG_0003}" severity="alert"
					widgetVar="confirmation">

					<p:commandButton value="#{lbls.LBL_0011}"
						update="pessoaDataTable, painelEdicao"
						oncomplete="confirmation.hide()"
						action="#{manterPessoaMB.doRemoverAction}" />

					<p:commandButton id="decline" value="#{lbls.LBL_0012}"
						onclick="confirmation.hide()" type="button" />

				</p:confirmDialog>
			</p:panel>

			<p:dataTable id="pessoaDataTable" var="pessoa" paginator="true"
				rows="5" emptyMessage="#{lbls.LBL_0004}" paginatorPosition="bottom"
				rowKey="#{pessoa.id}" value="#{manterPessoaMB.listaPessoa}"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
				<p:column style="width:10px;">
					<f:facet name="header">
						<h:outputText value="Código" />
					</f:facet>
					<div align="center">
						<h:outputText value="#{pessoa.id}" />
					</div>
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Nome" />
					</f:facet>
					<h:outputText value="#{pessoa.nome}" />
				</p:column>
				
				<p:column>
					<f:facet name="header">
						<h:outputText value="Tipo Pessoa" />
					</f:facet>
						<p:selectOneRadio id="radioPessoa"
								disabled="true"
								value="#{pessoa.pessoa}" 
								style="width:120px;">
							<f:selectItems var="pessoa" 
								value="#{manterPessoaMB.listaPessoas}" 
								itemLabel="#{pessoa.descricao}" 
								itemValue="#{pessoa}" />
						</p:selectOneRadio>
				</p:column>

				<p:column style="width:40px">
					<p:commandButton id="selectButton" update=":form1:painelEdicao"
						action="#{manterPessoaMB.doDetalharAction}" process="@this"
						icon="ui-icon-search" title="Visualizar">
						<f:setPropertyActionListener value="#{pessoa}"
							target="#{manterPessoaMB.pessoa}" />
					</p:commandButton>
				</p:column>

			</p:dataTable>

		</h:form>
	</ui:define>
</ui:composition>
</html>